let userIdHid = $("input[name='userIdHid']").val();
$(function () {
    //ajax异步加载推荐
    $.ajax({
        type: 'post',
        url: '/fr/index/recommend',
        success:function (res) {
            let list = res.data;
            let str = "";
            $.each(list,function (index,item) {
                str ="<li class=\"nav_item\">\n" +
                    "                <div class=\"like nolike\">\n" +
                    "                    <svg t=\"1648635351114\" class=\"iconR1\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2832\" data-spm-anchor-id=\"a313x.7781069.0.i3\" width=\"15\" height=\"15\">\n" +
                    "                        <path d=\"M461.1 887.1S210.6 784 98.3 552.5C46.6 446 46.3 303.3 147 202.1c100.6-101.1 263.8-101.2 364.4 0C612 101 775.2 101 875.8 202.1 976.5 303.3 979.1 458 924.5 552.5 789 787.1 570.3 885.1 570.3 885.1c-29.8 16.3-78.9 16.8-109.2 2z m20.1-41.4c17.3 8.5 50.7 7.9 66.8-1l3.6-1.7c2.7-1.2 8.5-4 17-8.5 14.6-7.8 31-17.3 48.8-28.6 51-32.6 102.1-73.1 149.7-121.9 45.2-46.3 85-97.7 117.8-154.5 50-86.6 36.9-216.2-41.5-294.9-82.7-83.1-216.6-83.1-299.2 0l-32.6 32.8-32.6-32.8c-82.7-83.1-216.6-83.1-299.3 0-78 78.4-89.5 195.7-40 297.8 33.6 69.1 82.8 130.8 143.9 185 43 38.2 89.2 70.4 135.4 96.7 16.2 9.2 31 16.9 44.3 23.3 7.8 3.7 13 6.1 15.5 7.1l2.4 1.2z\" fill=\"#666666\" p-id=\"2833\" data-spm-anchor-id=\"a313x.7781069.0.i4\" class=\"\"></path></svg>\n" +
                    "                " +
                    "</div>\n" +
                    "                <div class=\"like\">\n" +
                    "                    <svg t=\"1648635573502\" class=\"iconR2\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2974\" width=\"15\" height=\"15\">\n" +
                    "                        <path d=\"M512 901.746939c-13.583673 0-26.122449-4.179592-37.093878-13.061225-8.881633-7.314286-225.697959-175.020408-312.424489-311.379592C133.746939 532.37551 94.040816 471.24898 94.040816 384.522449c0-144.718367 108.146939-262.269388 240.326531-262.269388 67.395918 0 131.657143 30.82449 177.632653 84.636735 45.453061-54.334694 109.191837-84.636735 177.110204-84.636735 132.702041 0 240.326531 117.55102 240.326531 262.269388 0 85.159184-37.093878 143.673469-67.395919 191.216327l-1.044898 1.567346c-86.726531 136.359184-303.542857 304.587755-312.424489 311.379592-10.44898 8.359184-22.987755 13.061224-36.571429 13.061225z\" fill=\"#E5404F\" p-id=\"2975\"></path></svg>\n" +
                    "                </div>\n" +
                    "                <a href='/fr/storeInfo/enter/"+item.shopId+"' onclick='writerIndexHistory("+userIdHid+","+item.shopId+")'>" +
                    "                    <img src=\"/fr"+item.shopPicture+"\" alt=\"\">\n" +
                    "                </a>\n" +
                    "                <div class=\"rname\"><a href='/fr/storeInfo/enter/"+item.shopId+"' onclick='writerIndexHistory("+userIdHid+","+item.shopId+")'>"+item.shopName+"</a></div>\n" +
                    "                <div class=\"score\">\n" +
                    "                    <span>评分:"+item.shopScore+"</span>\n" +
                    "                    <span>"+item.commentCount+"条评论</span>\n" +
                    "                </div>\n" +
                    "                <div class=\"location\">\n" +
                    "                    <span>位于:"+item.province+""+item.city+"</span>\n" +
                    "                </div>\n" +"<input type='hidden' name='rec"+index+"' value='"+item.shopId+"'>"+
                    "                <input type='hidden' name='recStatus"+index+"' value='"+item.collectionStatus+"'>"+
                    "            </li>";
                $("#likes").append(str);
            });
            let width = 0;
            for (let i = 0; i < $('.nav_item').length; i++) {
                width += $('.nav_item').eq(i).outerWidth(true);
            }
            $('.nav_mine').width(width+20);  //width只是内容的宽度，需要加上padding的宽度

            $("#likes").find('.iconR1').each(function(index){
                if ($("input[name='recStatus"+index+"']").val()==1){
                    $(this).parent().css("z-index","10");
                    $(this).parent().next().css("z-index","11");
                }
                $(this).click(function(){
                    let userId = $("input[name='userIdHid']").val();
                    if (userId.length==0){

                    }else if(userId.length>0){
                        if (window.confirm("确认收藏店铺吗?")) {
                            $(this).parent().css("z-index","10");
                            $(this).parent().next().css("z-index","11");
                            $.ajax({
                                type: 'post',
                                url: '/fr/index/addRecommend/'+$("input[name='rec"+index+"']").val()+'/'+$("input[name='userIdHid']").val()+''
                            })
                        } else {
                            alert("亲，希望您能在这儿找到喜欢的店铺~~")
                        }
                    }
                });
            });
            $("#likes").find('.iconR2').each(function(index){
                $(this).click(function(){
                    let userId = $("input[name='userIdHid']").val();
                    if (userId.length==0){
                        alert("请您先登录在进行收藏操作!");
                    }else if(userId.length>0){
                        if (window.confirm("确认取消收藏店铺吗?")) {
                            $(this).parent().css("z-index","10");
                            $(this).parent().prev().css("z-index","11");
                            $.ajax({
                                type: 'post',
                                url: '/fr/index/cancelRecommend/'+$("input[name='rec"+index+"']").val()+'/'+$("input[name='userIdHid']").val()+''
                            })
                        } else {
                            alert("亲，希望您能在这儿找到其他喜欢的店铺~~")
                        }
                    }
                });

            });

        }
    })
})
$(function () {
    //ajax异步加载午餐推荐
    $.ajax({
        type: 'post',
        url: '/fr/index/recommendLunch',
        success:function (res) {
            let list = res.data;
            let str = "";
            $.each(list,function (index,item) {
                str +="<div class=\"fouritem\">\n" +
                    "                <div class=\"like nolike lunchl\">\n" +
                    "                    <svg t=\"1648635351114\" class=\"iconR1\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2832\" data-spm-anchor-id=\"a313x.7781069.0.i3\" width=\"15\" height=\"15\">\n" +
                    "                        <path d=\"M461.1 887.1S210.6 784 98.3 552.5C46.6 446 46.3 303.3 147 202.1c100.6-101.1 263.8-101.2 364.4 0C612 101 775.2 101 875.8 202.1 976.5 303.3 979.1 458 924.5 552.5 789 787.1 570.3 885.1 570.3 885.1c-29.8 16.3-78.9 16.8-109.2 2z m20.1-41.4c17.3 8.5 50.7 7.9 66.8-1l3.6-1.7c2.7-1.2 8.5-4 17-8.5 14.6-7.8 31-17.3 48.8-28.6 51-32.6 102.1-73.1 149.7-121.9 45.2-46.3 85-97.7 117.8-154.5 50-86.6 36.9-216.2-41.5-294.9-82.7-83.1-216.6-83.1-299.2 0l-32.6 32.8-32.6-32.8c-82.7-83.1-216.6-83.1-299.3 0-78 78.4-89.5 195.7-40 297.8 33.6 69.1 82.8 130.8 143.9 185 43 38.2 89.2 70.4 135.4 96.7 16.2 9.2 31 16.9 44.3 23.3 7.8 3.7 13 6.1 15.5 7.1l2.4 1.2z\" fill=\"#666666\" p-id=\"2833\" data-spm-anchor-id=\"a313x.7781069.0.i4\" class=\"\"></path></svg>\n" +
                    "                </div>\n" +
                    "                <div class=\"like lunchl\">\n" +
                    "                    <svg t=\"1648635573502\" class=\"iconR2\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2974\" width=\"15\" height=\"15\">\n" +
                    "                        <path d=\"M512 901.746939c-13.583673 0-26.122449-4.179592-37.093878-13.061225-8.881633-7.314286-225.697959-175.020408-312.424489-311.379592C133.746939 532.37551 94.040816 471.24898 94.040816 384.522449c0-144.718367 108.146939-262.269388 240.326531-262.269388 67.395918 0 131.657143 30.82449 177.632653 84.636735 45.453061-54.334694 109.191837-84.636735 177.110204-84.636735 132.702041 0 240.326531 117.55102 240.326531 262.269388 0 85.159184-37.093878 143.673469-67.395919 191.216327l-1.044898 1.567346c-86.726531 136.359184-303.542857 304.587755-312.424489 311.379592-10.44898 8.359184-22.987755 13.061224-36.571429 13.061225z\" fill=\"#E5404F\" p-id=\"2975\"></path></svg>\n" +
                    "                </div>\n" +
                    "                <a href='/fr/storeInfo/enter/"+item.shopId+"' onclick='writerIndexHistory("+userIdHid+","+item.shopId+")'>" +
                    "                    <img src=\"/fr"+item.shopPicture+"\" alt=\"\">\n" +
                    "                </a>\n" +
                    "                <div class=\"rname\"><a href='/fr/storeInfo/enter/"+item.shopId+"' onclick='writerIndexHistory("+userIdHid+","+item.shopId+")'>"+item.shopName+"</a></div>\n" +
                    "                <div class=\"score\">\n" +
                    "                    <span>评分:"+item.shopScore+"</span>\n" +
                    "                    <span>"+item.commentCount+"条评论</span>\n" +
                    "                </div>\n" +
                    "                <div class=\"location\">\n" +
                    "                    <span>位于:"+item.province+""+item.city+"</span>\n" +
                    "                </div>\n" +"<input type='hidden' name='recl"+index+"' value='"+item.shopId+"'>"+
                    "                <input type='hidden' name='reclStatus"+index+"' value='"+item.collectionStatus+"'>"+
                    "            </div>";
            });
            $("#likel").html(str);
            $("#likel").find('.iconR1').each(function(index){
                if ($("input[name='recStatus"+index+"']").val()==1){
                    $(this).parent().css("z-index","10");
                    $(this).parent().next().css("z-index","11");
                }
                $(this).click(function(){
                    let userId = $("input[name='userIdHid']").val();
                    if (userId.length==0){

                    }else if(userId.length>0){
                        if (window.confirm("确认收藏店铺吗?")) {
                            $(this).parent().css("z-index","10");
                            $(this).parent().next().css("z-index","11");
                            $.ajax({
                                type: 'post',
                                url: '/fr/index/addRecommend/'+$("input[name='recl"+index+"']").val()+'/'+$("input[name='userIdHid']").val()+''
                            })
                        } else {
                            alert("亲，希望您能在这儿找到喜欢的店铺~~")
                        }
                    }
                });
            });
            $("#likel").find('.iconR2').each(function(index){
                $(this).click(function(){
                    let userId = $("input[name='userIdHid']").val();
                    if (userId.length==0){
                        alert("请您先登录在进行收藏操作!");
                    }else if(userId.length>0){
                        if (window.confirm("确认取消收藏店铺吗?")) {
                            $(this).parent().css("z-index","10");
                            $(this).parent().prev().css("z-index","11");
                            $.ajax({
                                type: 'post',
                                url: '/fr/index/cancelRecommend/'+$("input[name='recl"+index+"']").val()+'/'+$("input[name='userIdHid']").val()+''
                            })
                        } else {
                            alert("亲，希望您能在这儿找到其他喜欢的店铺~~")
                        }
                    }
                });

            });

        }
    })
})
$(function () {
    //ajax异步加载晚餐推荐
    $.ajax({
        type: 'post',
        url: '/fr/index/recommendDinner',
        success:function (res) {
            let list = res.data;
            let str = "";
            $.each(list,function (index,item) {
                str +="<div class=\"fouritem\">\n" +
                    "                <div class=\"like nolike lunchl\">\n" +
                    "                    <svg t=\"1648635351114\" class=\"iconR1\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2832\" data-spm-anchor-id=\"a313x.7781069.0.i3\" width=\"15\" height=\"15\">\n" +
                    "                        <path d=\"M461.1 887.1S210.6 784 98.3 552.5C46.6 446 46.3 303.3 147 202.1c100.6-101.1 263.8-101.2 364.4 0C612 101 775.2 101 875.8 202.1 976.5 303.3 979.1 458 924.5 552.5 789 787.1 570.3 885.1 570.3 885.1c-29.8 16.3-78.9 16.8-109.2 2z m20.1-41.4c17.3 8.5 50.7 7.9 66.8-1l3.6-1.7c2.7-1.2 8.5-4 17-8.5 14.6-7.8 31-17.3 48.8-28.6 51-32.6 102.1-73.1 149.7-121.9 45.2-46.3 85-97.7 117.8-154.5 50-86.6 36.9-216.2-41.5-294.9-82.7-83.1-216.6-83.1-299.2 0l-32.6 32.8-32.6-32.8c-82.7-83.1-216.6-83.1-299.3 0-78 78.4-89.5 195.7-40 297.8 33.6 69.1 82.8 130.8 143.9 185 43 38.2 89.2 70.4 135.4 96.7 16.2 9.2 31 16.9 44.3 23.3 7.8 3.7 13 6.1 15.5 7.1l2.4 1.2z\" fill=\"#666666\" p-id=\"2833\" data-spm-anchor-id=\"a313x.7781069.0.i4\" class=\"\"></path></svg>\n" +
                    "                </div>\n" +
                    "                <div class=\"like lunchl\">\n" +
                    "                    <svg t=\"1648635573502\" class=\"iconR2\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"2974\" width=\"15\" height=\"15\">\n" +
                    "                        <path d=\"M512 901.746939c-13.583673 0-26.122449-4.179592-37.093878-13.061225-8.881633-7.314286-225.697959-175.020408-312.424489-311.379592C133.746939 532.37551 94.040816 471.24898 94.040816 384.522449c0-144.718367 108.146939-262.269388 240.326531-262.269388 67.395918 0 131.657143 30.82449 177.632653 84.636735 45.453061-54.334694 109.191837-84.636735 177.110204-84.636735 132.702041 0 240.326531 117.55102 240.326531 262.269388 0 85.159184-37.093878 143.673469-67.395919 191.216327l-1.044898 1.567346c-86.726531 136.359184-303.542857 304.587755-312.424489 311.379592-10.44898 8.359184-22.987755 13.061224-36.571429 13.061225z\" fill=\"#E5404F\" p-id=\"2975\"></path></svg>\n" +
                    "                </div>\n" +
                    "                <a href='/fr/storeInfo/enter/"+item.shopId+"' onclick='writerIndexHistory("+userIdHid+","+item.shopId+")'>" +
                    "                    <img src=\"/fr"+item.shopPicture+"\" alt=\"\">\n" +
                    "                </a>\n" +
                    "                <div class=\"rname\"><a href='/fr/storeInfo/enter/"+item.shopId+"' onclick='writerIndexHistory("+userIdHid+","+item.shopId+")'>"+item.shopName+"</a></div>\n" +
                    "                <div class=\"score\">\n" +
                    "                    <span>评分:"+item.shopScore+"</span>\n" +
                    "                    <span>"+item.commentCount+"条评论</span>\n" +
                    "                </div>\n" +
                    "                <div class=\"location\">\n" +
                    "                    <span>位于:"+item.province+""+item.city+"</span>\n" +
                    "                </div>\n" +"<input type='hidden' name='recn"+index+"' value='"+item.shopId+"'>"+
                    "                <input type='hidden' name='recnStatus"+index+"' value='"+item.collectionStatus+"'>"+
                    "            </div>";
            });
            $("#liken").html(str);
            $("#liken").find('.iconR1').each(function(index){
                if ($("input[name='recStatus"+index+"']").val()==1){
                    $(this).parent().css("z-index","10");
                    $(this).parent().next().css("z-index","11");
                }
                $(this).click(function(){
                    let userId = $("input[name='userIdHid']").val();
                    if (userId.length==0){

                    }else if(userId.length>0){
                        if (window.confirm("确认收藏店铺吗?")) {
                            $(this).parent().css("z-index","10");
                            $(this).parent().next().css("z-index","11");
                            $.ajax({
                                type: 'post',
                                url: '/fr/index/addRecommend/'+$("input[name='recn"+index+"']").val()+'/'+$("input[name='userIdHid']").val()+''
                            })
                        } else {
                            alert("亲，希望您能在这儿找到喜欢的店铺~~")
                        }
                    }
                });
            });
            $("#liken").find('.iconR2').each(function(index){
                $(this).click(function(){
                    let userId = $("input[name='userIdHid']").val();
                    if (userId.length==0){
                        alert("请您先登录在进行收藏操作!");
                    }else if(userId.length>0){
                        if (window.confirm("确认取消收藏店铺吗?")) {
                            $(this).parent().css("z-index","10");
                            $(this).parent().prev().css("z-index","11");
                            $.ajax({
                                type: 'post',
                                url: '/fr/index/cancelRecommend/'+$("input[name='recn"+index+"']").val()+'/'+$("input[name='userIdHid']").val()+''
                            })
                        } else {
                            alert("亲，希望您能在这儿找到其他喜欢的店铺~~");
                        }
                    }
                });

            });

        }
    })
})
function writerIndexHistory(userId,shopId) {
    console.log(userId+"::"+shopId),
    $.ajax({
        type:"post",
        url:"/fr/personal/history/"+userId+"/"+shopId+""
    })
}
